﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '编号', name: 'Id', width: "5%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '项目标题', name: 'ProjectName', width: "10%", sortable: false, align: 'left' },
                    { display: '项目分类', name: 'ProjectClassName', width: "7%", sortable: false, align: 'left' },
                    { display: '筹资金额(元)', name: 'Amount', width: "7%", sortable: false, align: 'left' },
                    { display: '筹集天数', name: 'CollectDays', width: "7%", sortable: false, align: 'left' },
                    //{ display: '一句话说明', name: 'ProjectAdWord', width: "7%", sortable: false, align: 'left' },
                    //{ display: '项目简介', name: 'ProjectSummary', width: "7%", sortable: false, align: 'left' },
                    //{ display: '项目详情', name: 'ProjectDetails', width: "7%", sortable: false, align: 'left' },
                    //{ display: '视频介绍', name: 'VideoAddr', width: "7%", sortable: false, align: 'left' },
                    //{ display: '首屏图片', name: 'ProjectThumImage', width: "7%", sortable: false, align: 'left' },
                    //{ display: '预热图片', name: 'ProjectThumImage1', width: "7%", sortable: false, align: 'left' },
                    { display: '创建时间', name: 'AuditTime', width: "7%", sortable: false, align: 'left' }, 
                    //{ display: '审核时间', name: 'AuditTime', width: "7%", sortable: false, align: 'left' },
                    //{ display: '未通过理由', name: 'RefuseReason', width: "7%", sortable: false, align: 'left' },
                    { display: '发布者', name: 'MemberName', width: "7%", sortable: false, align: 'left' },
                    { display: '审核管理员', name: 'AdminName', width: "7%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "13%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "Id",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            ops.push("&nbsp;<a title='投资档位' href='javascript:;'  onclick=\"util.Item('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资档位</a>");
            ops.push("&nbsp;<a title='投资详情' href='javascript:;'  onclick=\"util.InvestmentDetails('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>投资详情</a>");
            ops.push("&nbsp;<a title='满标' href='javascript:;'  onclick=\"util.ManBiao('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>满标</a>");
            ops.push("&nbsp;<a title='流标' href='javascript:;'  onclick=\"util.LiuBiao('", value, "')\"><i class='fa fa-edit' class='fa fa-trash-o'></i>流标</a>");
            return ops.join("");
        }

        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });

        $("#btnAdd").click(function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        });
        
        //投资档位
        util.Item = function (id) {
            var url = options.itemUrl + "/" + id;
            location.href = url;
        };
        
        //投资详情
        util.InvestmentDetails = function (id) {
            var url = options.investmentDetailsUrl + "/" + id;
            location.href = url;
        };

        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
        };

        //满标
        util.ManBiao = function(id) {
            if (!confirm("您确定要满标吗？这可是要负责的额。")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/ManBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&eventType=2"
            });
        };
        
        //流标
        util.LiuBiao = function (id) {
            if (!confirm("您确定要流标吗？这可是要负责的额。")) {
                return false;
            }
            $.ajax({
                url: "/ProjectMgr/ManBiao",
                type: "Post",
                success: function (data) {
                    var obj = JSON.parse(data);
                    alert(obj.errorMessage);
                    xjgrid.Reload();
                },
                data: "projectId=" + id + "&eventType=1"
            });
        };

    });

})(window, undefined, jQuery);